<cfmodule template="../../tag/layout.cfm">
<cfinclude template="../../inc/lib.cfm">
<!--- 表格显示 --->
<table id="grid"></table>
<div id="toolbar" style="display: none;">
	<form id="searchForm">
		<table>
			<tr>
				<td>标题</td>
				<td><input name="subject" style="width: 180px;" /></td>
				<td>创建时间</td>
				<td>
					<input name="created_ge"  class="easyui-datebox" style="width:100px"/>
					-
					<input name="created_le"  class="easyui-datebox" style="width:100px"/>
				</td>
				<td>
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.treegrid('load',fw.serializeObject($('#searchForm')));">过滤</a>
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.treegrid('load',{});">重置过滤</a>
				</td>
			</tr>
		</table>
	</form>
	
	<table>
		<tr>
			<cfif havePermission( queryStringDeleteVar('categoryid',queryStringDeleteVar('articlebaseid',QueryStringChangeVar('action',getCurrentPageType() & '.save')))  )>
			<td>
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_add',plain:true" onclick="addFun();">添加</a>
			</td>
			</cfif>
			<td>
				<a onclick="redoFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'ext-icon-resultset_next'">展开</a>
				<a onclick="undoFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'ext-icon-resultset_previous'">折叠</a>
			</td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td>
				<a onclick="grid.treegrid('reload');" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'ext-icon-arrow_refresh'">刷新</a>
			</td>
		</tr>
	</table>
</div>
</cfmodule>
<cfscript>
	if( structKeyExists(rc, "articlebaseid")  && rc.articlebaseid > 0 ){
		articlebaseid = rc.articlebaseid;
	}else{
		articlebaseid = 0;
	}
	
	if( structKeyExists(rc, "categoryid")  && rc.categoryid > 0 ){
		categoryid = rc.categoryid;
	}else{
		categoryid = 0;
	}
</cfscript>
<script type="application/javascript">
var closeDialog = function($dialog,$grid) {
	$dialog.dialog('destroy');
	$grid.datagrid('reload');
}
	
//删除操作
var removeFun = function(id) {
    parent.$.messager.confirm('询问', '您确定要删除此记录？',
    function(r) {
        if (r) {
            $.post('?action=articlecomment.delete', {
                id: id
            },
            function() {
                grid.treegrid('reload');
            },
            'json');
        }
    });
};

//查看操作
var showFun = function(id) {
    var dialog = parent.fw.modalDialog({
        title: '查看评论',
        url: '?action=articlecomment.form&id=' + id,
        buttons: [{
            text: '关闭窗口',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
};
//新增操作
var addFun = function() {
    var dialog = parent.fw.modalDialog({
        title: '新增评论',
        url: '?action=articlecomment.form&<cfoutput>categoryid=#categoryid#&articlebaseid=#articlebaseid#</cfoutput>',
        buttons: [
        {
            text: '新增记录',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
            }
        },{
            text: '关闭窗口',
            handler: function() {
               dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
}
//修改操作
var editFun = function(id) {
    var dialog = parent.fw.modalDialog({
        title: '修改评论',
        url: '?action=articlecomment.form&categoryid=<cfoutput>#categoryid#</cfoutput>&id=' + id,
        buttons: [
        {
            text: '修改记录',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
            }
        },{
            text: '关闭窗口',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
};	

//单条记录操作
var singleFun = function(type,id) {
	var url = "?action=articlecomment." + type;
	$.post(url, 
	{id:id},
	function() { 
		grid.treegrid('reload'); 
	},'json');
};

var replyFun = function(id) {
    var dialog = parent.fw.modalDialog({
        title: '新增评论',
        url: '?action=articlecomment.form&<cfoutput>categoryid=#categoryid#&articlebaseid=#articlebaseid#</cfoutput>&articlecommentid='+id,
        buttons: [
        {
            text: '新增记录',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
            }
        },{
            text: '关闭窗口',
            handler: function() {
               dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
}


var redoFun = function() {
	var node = grid.treegrid('getSelected');
	if (node) {
		grid.treegrid('expandAll', node.id);
	} else {
		grid.treegrid('expandAll');
	}
};
var undoFun = function() {
	var node = grid.treegrid('getSelected');
	if (node) {
		grid.treegrid('collapseAll', node.id);
	} else {
		grid.treegrid('collapseAll');
	}
};

$(function(){
	//列表操作
	var gird;
	grid = $('#grid').treegrid({
		fit:true,
	    border:false,
        rownumbers: true,
        animate:false,
        collapsible:false,
        fitColumns:true,
        pagination: true,
        url:'?action=articlecomment.list&articlebaseid=<cfoutput>#articlebaseid#</cfoutput>',
        idField:'id',
        treeField:'subject',
        columns:[[
            {title:'id',field:'id',width:'50',hidden: false},
            {field:'subject',title:'评论标题',width:'200',sortable:true,},
            {field:'createdip',title:'IP地址',width:'100'},
            {field:'ispublish',title:'发布',width:50,sortable:true,align:'center',
				formatter:function(value,row){
					var str = '';
					if(!value){
						str = "<span style='color:red'>未发布</span>";
					}
					return str;
				}
			},
            {field:'seq',title:'排序',width:'50',sortable:true,align:'center'},
            {field:'created',title:'评论时间',width:80,align:'center',sortable:true},
			{field:'edited',title:'修改时间',width:80,align:'center',sortable:true}, 
	        {
				title : '操作',
				field : 'action',
				width : '60',
				formatter : function(value, row) {
					var str = '';
					
					<cfif havePermission( queryStringDeleteVar('categoryid',queryStringDeleteVar('articlebaseid',QueryStringChangeVar('action',getCurrentPageType() & '.form')))  )>
					str += fw.formatString('<img class="iconImg ext-icon-note" title="查看" onclick="showFun(\'{0}\');"/>', row.id);
					</cfif>
					
					<cfif havePermission( queryStringDeleteVar('categoryid',queryStringDeleteVar('articlebaseid',QueryStringChangeVar('action',getCurrentPageType() & '.update')))  )>
					str += fw.formatString('<img class="iconImg ext-icon-note_edit" title="编辑" onclick="editFun(\'{0}\');"/>', row.id);
					</cfif>
					
					<cfif havePermission( queryStringDeleteVar('categoryid',queryStringDeleteVar('articlebaseid',QueryStringChangeVar('action',getCurrentPageType() & '.delete')))  )>
					str += fw.formatString(' <img class="iconImg ext-icon-note_delete" title="删除" onclick="removeFun(\'{0}\');"/>', row.id);
					</cfif>
					
					<cfif havePermission( queryStringDeleteVar('categoryid',queryStringDeleteVar('articlebaseid',QueryStringChangeVar('action',getCurrentPageType() & '.publish')))  )>
					str += fw.formatString(' <img class="iconImg ext-icon-key" title="发布" onclick="singleFun(\'publish\',{0});"/>', row.id);
					</cfif>
					
					<cfif havePermission( queryStringDeleteVar('categoryid',queryStringDeleteVar('articlebaseid',QueryStringChangeVar('action',getCurrentPageType() & '.reply')))  )>
					str += fw.formatString(' <img class="iconImg ext-icon-comment_edit" title="回复" onclick="replyFun(\'{0}\');"/>', row.id);
					</cfif>
					
					return str;
				}
			}
        ]],
        toolbar: '#toolbar',
        onBeforeLoad: function(row,param){
            if (!row) {    // load top level rows
                param.articlecommentid = 0;    // set id=0, indicate to load new page rows
            }
        },
		onLoadSuccess : function(data) {
			$('.iconImg').attr('src', fw.pixel_0);
			grid.treegrid('expandAll');
		}
    });
	
	
});
</script>